package ltd.util;

/**
 * Created by chinalin on 2017/4/10.
 */
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 改为使用appcontext里生成，controller里注解注入
 *
 * 在web.xml里设置本监听才能使用
 */
@Deprecated
public class SpringContextUtil implements ServletContextListener  {

    private static WebApplicationContext springContext = null ;

    public void contextDestroyed(ServletContextEvent event) {
    }

    public void contextInitialized(ServletContextEvent event) {
        springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
    }

    public static WebApplicationContext getSpringContext() {
        return springContext;
    }

    public static Object getBean(String name){
        return springContext.getBean(name);
    }

}
